package com.rrd.mex.dw.mr.babel;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.euler.commons.web.SystemID;
import com.rrd.mex.dw.mr.babel.parser.MexCalendarRecordParse;
import com.rrd.mex.dw.mr.babel.parser.ParseBase;
import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.hfq.calendar.UploadCalendarRecord;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class TestJosn {
    protected void parseValue(BaseModel<?> model, ParseBase parser, Mapper.Context context) throws IOException, InterruptedException {
        String successful = "1";
        if (model != null) {
            if (parser.parseJob(context, model, successful)) {
                context.getCounter("counter", "user." + parser.getType() + parser.getSubType()).increment(1);
            } else {
//                    context.getCounter("counter", "user." + parser.getType() + parser.getSubType() + ".false").increment(1);
            }
        } else {
            context.getCounter("error", "user." + parser.getType() + parser.getSubType() + ".null").increment(1);
        }
    }
    public static void main(String[] args) throws Exception {
        InputStreamReader isr = new InputStreamReader(new FileInputStream("D:\\tmp\\a1.txt"));
        BufferedReader br = new BufferedReader(isr);
        String line = br.readLine();
        while (line!=null){
            System.out.println(line);
            JSONObject jsonObj = JSON.parseObject(line);
            String type = jsonObj.getString("type");
            System.out.println(type);
            if (!type.equals("HFQ_UPLOAD_CALENDAR_RECORD")){
                continue;
            }
            SystemID mx= SystemID.MexLoan;
            System.out.println(mx);
//            UploadCalendarRecord ss = new UploadCalendarRecord();
            UploadCalendarRecord record  = JSONObject.parseObject(line,UploadCalendarRecord.class);
//            PostRecord record = JsonMapperBuilder.build().readValue(line, PostRecord.class);
//            BaseModel<?> model = (BaseModel<?>) record.getRecord();
            MexCalendarRecordParse parser =new MexCalendarRecordParse();

            parser.parseJob(null,record,"1");

            line = br.readLine();
        }
        br.close();


    }
}
